﻿using System.Collections.Generic;
using SARS.Biz.Facades;
using SARS.DAO;
using SARS.DAO.Facades;
using SARS.Entity;

namespace SARS.Biz
{
    public class StudentAbsentReasonBO : IStudentAbsentReasonBO
    {
        private readonly IStudentAbsenceReasonDAO _dao = new StudentAbsenceReasonDAO();
        private readonly ISessionDAO _sessionDao = new SessionDAO();
        private readonly IUserDAO _user = new UserDAO();
        private readonly IRoomDAO room = new RoomDAO();

        public int InsertStudentAbsenceReason(StudentAbsenceReasonEntity entities)
        {
            return _dao.InsertStudentAbsenceReason(entities);
        }

        public List<StudentAbsenceReasonEntity> GetAllStudentAbsenceReasonByTutorId(int tutorId)
        {
            List<StudentAbsenceReasonEntity> list = _dao.GetAllStudentAbsenceReasonByTutorId(tutorId);
            foreach (StudentAbsenceReasonEntity absence in list)
            {
                absence.AttendanceSession.Session = _sessionDao.GetSessionById(absence.AttendanceSession.SessionID);
                absence.AttendanceSession.Session.Room = room.RetrieveRoomById(absence.AttendanceSession.Session.RoomID);
                absence.AttendanceSession.Student =
                    (StudentEntity) _user.RetrieveUserById(absence.AttendanceSession.StudentID);
            }

            return list;
        }

        public StudentAbsenceReasonEntity GetStudentAbsenceReasonById(int absentReasonId)
        {
            return _dao.GetStudentAbsenceReasonById(absentReasonId);
        }


        public int UpdateStudentAbsenceReason(StudentAbsenceReasonEntity entities)
        {
            return _dao.UpdateStudentAbsenceReason(entities);
        }
    }
}